package com.nmsl.sn.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.nmsl.common.annotation.Log;
import com.nmsl.common.core.controller.BaseController;
import com.nmsl.common.core.domain.AjaxResult;
import com.nmsl.common.enums.BusinessType;
import com.nmsl.sn.domain.SnPatient;
import com.nmsl.sn.service.ISnPatientService;
import com.nmsl.common.utils.poi.ExcelUtil;
import com.nmsl.common.core.page.TableDataInfo;

/**
 * 患者接诊Controller
 * 
 * @author sn
 * @date 2025-02-15
 */
@RestController
@RequestMapping("/sn/patient")
public class SnPatientController extends BaseController
{
    @Autowired
    private ISnPatientService patientService;

    /**
     * 查询患者接诊列表
     */
    @PreAuthorize("@ss.hasPermi('sn:patient:list')")
    @GetMapping("/list")
    public TableDataInfo list(SnPatient patient)
    {
        startPage();
        List<SnPatient> list = patientService.selectPatientList(patient);
        return getDataTable(list);
    }

    /**
     * 导出患者接诊列表
     */
    @PreAuthorize("@ss.hasPermi('sn:patient:export')")
    @Log(title = "患者接诊", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SnPatient patient)
    {
        List<SnPatient> list = patientService.selectPatientList(patient);
        ExcelUtil<SnPatient> util = new ExcelUtil<SnPatient>(SnPatient.class);
        util.exportExcel(response, list, "患者接诊数据");
    }

    /**
     * 获取患者接诊详细信息
     */
    @PreAuthorize("@ss.hasPermi('sn:patient:query')")
    @GetMapping(value = "/{patientId}")
    public AjaxResult getInfo(@PathVariable("patientId") Long patientId)
    {
        return success(patientService.selectPatientByPatientId(patientId));
    }

    /**
     * 新增患者接诊
     */
    @PreAuthorize("@ss.hasPermi('sn:patient:add')")
    @Log(title = "患者接诊", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SnPatient patient)
    {
        return toAjax(patientService.insertPatient(patient));
    }

    /**
     * 修改患者接诊
     */
    @PreAuthorize("@ss.hasPermi('sn:patient:edit')")
    @Log(title = "患者接诊", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SnPatient patient)
    {
        System.out.println(patient);
        return toAjax(patientService.updatePatient(patient));
    }

    /**
     * 删除患者接诊
     */
    @PreAuthorize("@ss.hasPermi('sn:patient:remove')")
    @Log(title = "患者接诊", businessType = BusinessType.DELETE)
	@DeleteMapping("/{patientIds}")
    public AjaxResult remove(@PathVariable Long[] patientIds)
    {
        return toAjax(patientService.deletePatientByPatientIds(patientIds));
    }
}
